from django.db import models
from django.contrib.auth.models import AbstractUser
from utils.models import BaseModel


class User(AbstractUser):
    # 创建手机号字段
    mobile = models.CharField(max_length=11 , unique=True)
    email_active = models.BooleanField(default=False)

    # 创建默认地址
    default_address = models.ForeignKey('Address' , on_delete=models.SET_NULL , null=True, blank=True , related_name='users')


    class Meta:
        db_table = 'User'

class Address(BaseModel):
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='address')
    receiver = models.CharField(max_length=20)
    province = models.ForeignKey('areas.AreaModles', on_delete=models.PROTECT, related_name='province_address')
    city = models.ForeignKey('areas.AreaModles', on_delete=models.PROTECT, related_name='city_address')
    district = models.ForeignKey('areas.AreaModles', on_delete=models.PROTECT, related_name='district_address')
    place = models.CharField(max_length=50)
    mobile = models.CharField(max_length=11)
    tel = models.CharField(max_length=20, null=True, blank=True, default='')
    email = models.CharField(max_length=20, null=True, blank=True, default='')
    is_delete = models.BooleanField(default=False)

    class Meta:
        db_table = 'address'

